export default ({ request, serviceForMock, mock, faker }) => {

  // Mock数据配置 - 保留用于开发测试
  
  // 树形结构数据Mock
  mock.onGet('/tenant/tree/list').reply(200, {
    code: 0,
    msg: 'success',
    data: [
      {
        id: 1,
        label: '楼栋用房分类',
        children: [
          {
            id: 2,
            label: '宿舍',
            children: [
              {
                id: 3,
                label: 'A栋',
                children: [
                  { id: 4, label: '101', roomId: 101, buildingId: 3 },
                  { id: 5, label: '102', roomId: 102, buildingId: 3 },
                  { id: 6, label: '103', roomId: 103, buildingId: 3 },
                  { id: 7, label: '104', roomId: 104, buildingId: 3 }
                ]
              }
            ]
          },
          {
            id: 8,
            label: '二层',
            children: [
              {
                id: 9,
                label: 'B栋',
                children: [
                  { id: 10, label: '201', roomId: 201, buildingId: 9 },
                  { id: 11, label: '202', roomId: 202, buildingId: 9 },
                  { id: 12, label: '203', roomId: 203, buildingId: 9 }
                ]
              }
            ]
          }
        ]
      }
    ]
  })

  mock.onGet('/tenant/account/list').reply(config => {
    const params = new URLSearchParams(config.url.split('?')[1] || '')
    const roomId = params.get('roomId')
    const tab = params.get('tab') || 'tenant'
    
    // 根据房间ID和标签页生成不同的数据
    let mockData = []
    
    if (roomId) {
      // 如果选择了具体房间，显示该房间的租户信息
      if (tab === 'tenant') {
        mockData = [
          {
            id: 1,
            roomNumber: roomId,
            userName: 'admin',
            contactPhone: '13270889900',
            loginPassword: '111333',
            contactAddress: '否',
            totalMeter: '曹志华',
            createTime: '2025-01-12 15:30:00'
          }
        ]
      } else {
        mockData = Array.from({ length: 5 }, (_, index) => ({
          id: index + 1,
          roomNumber: roomId,
          userName: '曹志华',
          paymentMethod: '请选择',
          electricPlan: '请选择',
          timePlan: '请选择',
          waterPlan: '请选择',
          subsidyPlan: '请选择',
          depositAmount: '请输入',
          feeAmount: '请输入',
          publicAmount: '请输入'
        }))
      }
    } else {
      // 默认显示所有数据
      if (tab === 'tenant') {
        mockData = Array.from({ length: 10 }, (_, index) => ({
          id: index + 1,
          roomNumber: `10${index + 1}`,
          userName: 'admin',
          contactPhone: '13270889900',
          loginPassword: index % 2 === 0 ? '111333' : '******',
          contactAddress: index % 2 === 0 ? '否' : '是',
          totalMeter: '曹志华',
          createTime: '2025-01-12 15:30:00'
        }))
      } else {
        mockData = Array.from({ length: 10 }, (_, index) => ({
          id: index + 1,
          roomNumber: `10${index + 1}`,
          userName: '曹志华',
          paymentMethod: '请选择',
          electricPlan: '请选择',
          timePlan: '请选择',
          waterPlan: '请选择',
          subsidyPlan: '请选择',
          depositAmount: '请输入',
          feeAmount: '请输入',
          publicAmount: '请输入'
        }))
      }
    }
    
    return [200, {
      code: 0,
      msg: 'success',
      data: {
        page: {
          totalCount: mockData.length,
          pageSize: 10,
          totalPage: Math.ceil(mockData.length / 10),
          currPage: 1,
          list: mockData
        }
      }
    }]
  })

  mock.onGet('/tenant/monitor/list').reply(200, {
    code: 0,
    msg: 'success',
    data: {
      page: {
        totalCount: 10,
        pageSize: 10,
        totalPage: 1,
        currPage: 1,
        list: Array.from({ length: 10 }, (_, index) => ({
          id: index + 1,
          sequence: index + 1,
          tenantName: faker.name.findName(),
          balance: faker.random.number({ min: 20, max: 50 }),
          prepaidAmount: faker.random.number({ min: 20, max: 50 }),
          feeAmount: faker.random.number({ min: 15, max: 25 }),
          chargeTime: '2025-05-02 15:30:00',
          status: index % 2 === 0 ? '是' : '否'
        }))
      }
    }
  })

  mock.onPost('/tenant/account/save').reply(200, {
    code: 0,
    msg: '保存成功'
  })

  mock.onPost('/tenant/account/update').reply(200, {
    code: 0,
    msg: '更新成功'
  })

  mock.onPost('/tenant/account/delete').reply(200, {
    code: 0,
    msg: '删除成功'
  })

  return {
    // 获取树形结构数据
    tenant_tree_list(params = {}) {
      return request({
        url: '/tenant/tree/list',
        params
      })
    },

    // 租户开户管理
    tenant_account_list(params = {}) {
      return request({
        url: '/tenant/account/list',
        params
      })
    },

    tenant_account_info(params = {}) {
      return request({
        url: '/tenant/info/' + params.id,
        params
      })
    },

    tenant_account_save(data = {}) {
      return request({
        url: '/tenant/save',
        method: 'post',
        data
      })
    },

    tenant_account_update(data = {}) {
      return request({
        url: '/tenant/save',
        method: 'post',
        data
      })
    },

    tenant_account_delete(data = {}) {
      return request({
        url: '/tenant/delete',
        method: 'post',
        data
      })
    },

    // 租户监控
    tenant_monitor_list(params = {}) {
      return request({
        url: '/tenant/monitor/list',
        params
      })
    },

    // 初始化测试数据
    tenant_init_data() {
      return request({
        url: '/tenant/init-data',
        method: 'post'
      })
    }
  }
}

